package com.asdc.demo.dead;

import com.asdc.demo.utils.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.impl.AMQBasicProperties;

import java.util.Map;

/**
 * @ClassName Consumer01
 * @Author bsy
 * @Description 这个是正常队列
 * @Date 2022/3/13 23:01
 * @Version 1.0
 */
public class Consumer01 {
    private static final String NOMAL_EXCHAGE = "nomal_exchage";
    private static final String DEAD_EXCHAGE = "daad_exchage";
    private static final String NOMAL_QUEUE = "nomal_queue";
    private static final String DEAD_QUEUE = "dead_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        //成为死信消息后如何发到死信队列
        Map<String, Object> arguments = (Map<String, Object>) new AMQP.BasicProperties()
                .builder()
                .expiration("1000")
                .build();
        arguments.put("x-dead-letter-exchange",DEAD_EXCHAGE);
        arguments.put("x-dead-letter-routing-key","dead-routing-key");
        channel.exchangeDeclare(NOMAL_EXCHAGE, BuiltinExchangeType.DIRECT, false, false, arguments);
        channel.exchangeBind(DEAD_QUEUE,DEAD_EXCHAGE,"dead-routing-key");

    }

}
